Skip to content

Fix vendored gems breaking the Docker gem layer without a word (#2326) - #2425

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-vendored-gem-docker-layer-hint
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
agent/fix-vendored-gem-docker-layer-hint

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2326

Summary

After scan --mode vendored (or vendor) patches a gem, the usual Dockerfile gem layer stops building, and nothing told the user:

COPY Gemfile Gemfile.lock ./
RUN bundle install        # The path `…/.socket/vendor/gem/<uuid>/rack-2.2.8` does not exist.

This PR makes the vendored run say so, and documents it. It changes human output and docs only: no file the run writes, no JSON, no event, no warning code and no exit status changes.

  • Next step. When the run vendored a gem for Bundler and a Dockerfile or Containerfile in the project root runs bundle install in a stage that copied the Gemfile or its lock but not the project or .socket, the Next steps: block gains a third line:

    3. Dockerfile runs `bundle install` with only the Gemfile and its lock in the image, and the vendored gems are `path:` gems under .socket/vendor/: add `COPY .socket/vendor ./.socket/vendor` before that step, or the image build fails there with "The path … does not exist".
    

    The COPY it names follows the Gemfile's destination (/app/.socket/vendor after COPY Gemfile Gemfile.lock /app/).

  • Docs. docs/ecosystems.md gains "Ruby gems: vendored gems in a Docker build" (the Bun section already documents this case for Bun), and CLI_CONTRACT.md describes the new step.

Root cause

A vendored gem is a path: gem under .socket/vendor/gem/, so bundle install needs that directory wherever it runs. The gem layer that rails new writes copies only the Gemfile pair before the install. The vendored close named only the commit and the reinstall, and the Ruby docs did not mention Docker.

How the Dockerfile is read

crates/socket-patch-cli/src/commands/docker_hints.rs is a small reader of one file's instructions. It is a heuristic that only ever adds one line of advice, and it is built to stay silent when it cannot tell:

  • per stage, it notes a COPY/ADD of Gemfile, Gemfile.lock or Gemfile* from the build context, and a copy of ., .socket, .socket/vendor or .socket/vendor/gem; a stage built on an earlier one (FROM base AS build) starts from that stage's state;
  • it reports the first RUN that calls bundle install (also bin/bundle, bundler, a version selector, the JSON form, a here-document) with the pair copied and the vendored gems not;
  • it handles line continuations, flags (--chown, --link), the JSON form of COPY, CRLF files and comments;
  • it does not expand build arguments or read .dockerignore, skips a COPY --from=, and does not judge a RUN with a bind mount or one that sets BUNDLE_GEMFILE=.

A gem committed for a rules_ruby hub of a Bazel workspace is not a path: gem, so a run that vendored only such gems prints no step.

Evidence

What Test
#2326: the vendored run names the missing COPY for the rails new gem layer vendor_gem_docker_layer::a_gem_layer_without_the_vendor_dir_gets_a_next_step (CLI vendor suite)
The same for a Containerfile vendor_gem_docker_layer::a_containerfile_is_read_too
No step when the layer has the directory, copies the project first, or there is no Dockerfile vendor_gem_docker_layer::a_layer_that_copies_the_vendor_dir_gets_no_step
The reader: spellings of the copy and the install, destinations, stages, here-documents, what it leaves alone 9 unit tests in commands::docker_hints::tests

Red before the fix (commit 76b490f holds the tests alone):

$ cargo test -p socket-patch-cli --test vendor -- vendor_gem_docker_layer
no next step names the Dockerfile:
Vendored 1 package.
Next steps:
  1. Commit .socket/vendor/ and the updated lockfiles to make the patches portable.
  2. Reinstall from the updated lockfile, then run `socket-patch vex` to verify the installed patches.
test result: FAILED. 1 passed; 2 failed

Green on this branch:

$ cargo test -p socket-patch-cli --test vendor            149 passed
$ cargo test -p socket-patch-cli --lib                    1094 passed
$ cargo test -p socket-patch-cli --test e2e_vendor_gem_build -- --ignored   14 passed (Bundler 4.0.18, Ruby 3.3)
$ cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings   clean

cargo clippy --all-targets reports errors in test files this PR does not touch (tests/prebuilt_common, tests/common, scan/discovery.rs tests); they are there on main too, and CI's clippy job does not lint test targets.

That COPY .socket/vendor beside the pair makes a fresh bundle install pass is what the existing fresh-checkout tests of e2e_vendor_gem_build cover; the failure without it is the measurement in #2326. I did not build a Docker image.

Review

/code-review high ran on the first push and returned 10 findings. Fixed in 200f593, each with a unit test: a destination without a trailing slash, sources that only start with .socket, COPY *, stages built on earlier stages, here-documents, bin/bundle and bundler, the JSON form with a space in a path, and gems.rb (vendored mode refuses such a project, so it is no longer read as the pair).

Not fixed, because each one only keeps the step silent or is rare, and a reader that is certain would need a real Dockerfile parser:

  • Where a copy of .socket puts it is not checked (COPY .socket /tmp/ counts as the fix). Silent, not wrong.
  • Any bind mount on the RUN leaves it unjudged, also a mount of one file. Silent, not wrong.
  • A bare bundle (install is its default command) is not seen as an install: after splitting the command line into words there is no telling it from bundle followed by the next command.
  • RUN echo "… bundle install …" counts as an install, and so does bundle install --gemfile=other. Matching --gemfile anywhere in the line silenced the stock Rails Dockerfile (bootsnap precompile --gemfile), so only BUNDLE_GEMFILE= is honored.

Follow-ups

  • A .dockerignore that excludes .socket breaks the build the same way; the docs say so, the run does not check it.
  • The other vendored ecosystems whose artifacts are files in the repository (npm, pnpm, Yarn, Bun, PyPI, Composer) have the same Docker layer problem; only Bun's is documented. Not in this PR.

https://claude.ai/code/session_011f9aeQudUKeWbvpP6NwpQK


Generated by Claude Code

Empty commit that opens the draft pull request for #2326.

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQudUKeWbvpP6NwpQK
A vendored gem is a path gem under .socket/vendor/, so a Dockerfile
that copies only the Gemfile pair before bundle install stops
building (#2326). These tests ask the vendored close for a next step
that names the missing COPY, and for none when the layer has the
directory. They fail until the step is added.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQudUKeWbvpP6NwpQK
Assisted-by: Claude Code:claude-fable-5-2
After a vendored run, the usual Dockerfile gem layer (COPY Gemfile
Gemfile.lock, then bundle install) fails with "The path ... does
not exist": the vendored gems are path gems under .socket/vendor/,
which that step does not copy. Nothing said so.

The vendored close now adds a next step when a Dockerfile or
Containerfile in the project root runs bundle install in a stage
that copied the Gemfile or its lock and neither the project nor
.socket. It names the COPY to add, beside the copied Gemfile. The
step is human output only: no event, code or exit status changes.

The Ruby docs gain a section on vendored gems in a Docker build, and
the contract describes the new step.

Fixes #2326

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQudUKeWbvpP6NwpQK
Assisted-by: Claude Code:claude-fable-5-2
Review of the Docker gem layer step found advice that could be wrong
and layers it missed:

- A Gemfile copied to a directory written without a slash (/app)
  gave a COPY into its parent.
- Any source starting with .socket counted as the vendored gems
  (.socket/manifest.json, .socketrc), as did the flattening COPY *.
- A stage built on an earlier stage started empty, so the pair or
  the fix made in a base stage was not seen.
- An install in a RUN here-document, or spelled bin/bundle or
  bundler, was not seen, and a JSON-form COPY lost a path with a
  space.
- gems.rb counted as the pair, though vendored mode refuses it.

A RUN that sets BUNDLE_GEMFILE is left unjudged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQudUKeWbvpP6NwpQK
Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 21:48
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Human-only advisory output and documentation; no changes to patch application, lockfiles, or machine-readable CLI contracts.

Overview
Vendored Ruby gems become path: entries under .socket/vendor/, which breaks the common Docker pattern that copies only Gemfile/Gemfile.lock before bundle install. This PR warns users in human "Next steps:" output (step 3) when root Dockerfile or Containerfile looks like that pattern, suggesting a concrete COPY .socket/vendor … line aligned with where the Gemfile was copied.

A new docker_hints module implements a lightweight, stage-aware scan of Dockerfile instructions (continuations, heredocs, JSON COPY, multi-stage FROM … AS). It only speaks up when a stage runs bundle install after copying the Gemfile pair and before anything that includes vendored gems; it stays silent on bind mounts, BUNDLE_GEMFILE=, full-context copies, etc. vendor calls it when the run applied Bundler gems (excluding Bazel-only gem commits).

Docs (CLI_CONTRACT.md, docs/ecosystems.md) document the behavior and limitations (no .dockerignore, build-arg expansion). Tests cover the heuristic and end-to-end human output; shared vendor test helpers gain a non-JSON runner. No change to written files, JSON, events, warning codes, or exit status.

Reviewed by Cursor Bugbot for commit 200f593. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. After a vendored run patches a Bundler gem, it reads a Dockerfile/Containerfile in the project root and, when a stage runs bundle install after copying only the Gemfile pair, adds a third "Next steps" line naming the COPY .socket/vendor … that layer needs. It also documents the case in docs/ecosystems.md. Human output only: no JSON, event, warning code, written file or exit status changes.

Risk: low. The reader can only add one line of advice and stays silent when it can't read the file or can't tell what the Dockerfile does. It cannot fail a run.

Look here

  • vendor.rs:5006: when the step is printed (gems > for_bazel)
  • [docker_hints.rs:46](https://github.com/SocketDev/socket-patch/blob/200f59371c3703a1d94dc494e2c6ca7b95cc099a/crates/socket-patch-cli/src/commands/docker_hints.rs#L46-L102): per-stage tracking, and which RUNs are skipped (bind mount, BUNDLE_GEMFILE=)
  • [docker_hints.rs:193](https://github.com/SocketDev/socket-patch/blob/200f59371c3703a1d94dc494e2c6ca7b95cc099a/crates/socket-patch-cli/src/commands/docker_hints.rs#L193-L200): what counts as bringing the vendored gems in
  • [docker_hints.rs:243](https://github.com/SocketDev/socket-patch/blob/200f59371c3703a1d94dc494e2c6ca7b95cc099a/crates/socket-patch-cli/src/commands/docker_hints.rs#L243-L260): how the suggested destination is worked out
  • docs/ecosystems.md:5155: the new docs section

Verified

  • Read the whole diff against the description and Vendored gems break the usual Dockerfile gem layer (COPY Gemfile Gemfile.lock ./ then bundle install), and neither the scan output nor the Ruby docs say to copy .socket/vendor/ #2326. CHANGELOG.md is untouched. No debug code or unrelated edits; the test-helper refactor in vendor_gem_lockfile_only_e2e.rs only splits out a non-JSON runner.
  • Ran cargo test -p socket-patch-cli --lib docker_hints (9 passed) and --test vendor -- vendor_gem_docker_layer (3 passed) on the head. The PR's commit 76b490f has the tests without the fix, and the description shows them failing there.
  • CRLF is handled (str::lines). A read error or a missing file returns None. A Windows-style `# escape=`` Dockerfile isn't joined across lines, so it gives no hint rather than a wrong one.
  • CI on 200f593: ci-ok and clippy are green. Cursor Bugbot has been stuck "in progress" since 21:48Z and has posted no findings. It isn't a required check. No review threads.

Changes I made: none.

Open questions: none. Minor: for_bazel counts every event with the Bazel advisory code, not only applied gem events. In a mixed run where that count doesn't line up, the step stays silent rather than wrong.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026
One conflict, in docs/ecosystems.md: main added the agent-mode
paragraphs to "Ruby gems: gems already installed" where this branch
adds the section "Ruby gems: vendored gems in a Docker build". Both
are kept, main's paragraphs first since they close the section above.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed the full diff at bb4df6b: the Docker gem layer hint prints only in human output after a non-dry-run vendored gem apply, and an unreadable Dockerfile cannot fail the run. No blocking defects.

Non-blocking notes (each only yields one wrong advice line)
  • docker_hints.rs:214-236: splitting on &, ; and | loses command boundaries, so RUN mkdir -p /usr/local/bundle && install -d /x after the Gemfile copy is read as bundle install.
  • docker_hints.rs:144-157: RUN echo 1<<3 is read as a here-document with terminator 3, which hides a later COPY . ..
  • vendor.rs:5394: gems > for_bazel compares gem events with every event carrying the Bazel advisory code; a mixed run can keep the step silent.

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 03663a1 Dec 2, 2026
50 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-vendored-gem-docker-layer-hint branch December 2, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

3 participants